#include "iic.h"

void delay(unsigned char ms)
{
	unsigned int i ;
	for(ms;ms>0;ms--)
		for(i=921;i>0;i--);
}

void writeAt24c02(unsigned char Addr,Data)
{
	EA = 0;
	IIC_Start();
	IIC_SendByte(SlaveAddrW);
	IIC_WaitAck();
	IIC_SendByte(Addr);
	IIC_WaitAck();
	IIC_SendByte(Data);
	IIC_Ack(0);
	IIC_Stop();
	delay(5);
	EA = 1;
}

unsigned char readAt24c02(unsigned char Addr)
{
	unsigned char dat;
	EA = 0;
	IIC_Start();
	IIC_SendByte(SlaveAddrW);
	IIC_WaitAck();
	IIC_SendByte(Addr);
	IIC_WaitAck();
	IIC_Stop();
	somenop;
	
	
	IIC_Start();
	IIC_SendByte(SlaveAddrR);
	IIC_WaitAck();
	dat = IIC_RecByte();
	IIC_Ack(0);
	IIC_Stop();
	EA = 1;
	return dat;
}